package com.qutan.app;

import com.qutan.app.core.cache.InfoCache;
import com.qutan.app.core.cache.SceneCache;
import com.qutan.app.core.cache.redisConfig.JedisClusterFactory;
import com.qutan.app.quartz.JopRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ImportResource;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import redis.clients.jedis.JedisCluster;

/**
 * Created by pwy on 14-6-17.
 */
@SpringBootApplication
@EnableAutoConfiguration(exclude = {FreeMarkerAutoConfiguration.class})
@EnableTransactionManagement
@EnableScheduling
//@ImportResource({"classpath:dubboProvider.xml"}) //加入spring的bean的xml文件*/
public class BootstrapQuartzApi extends SpringBootServletInitializer {

    public static ApplicationContext applicationContext=null;

    public static void main(String[] args) throws Exception {
        System.setProperty("java.net.preferIPv4Stack" , "true");
        SpringApplication app = new SpringApplication(BootstrapQuartzApi.class);
        applicationContext = app.run(args);

        //cacheHandler.initCache();

        //JedisCluster jedisPool =applicationContext.getBean("jedisCluster",JedisCluster.class);

       // String test= jedisPool.get("hello");

       // System.err.println(test);

        SceneCache cacheHandler=applicationContext.getBean("sceneCache",SceneCache.class);
        cacheHandler.initCache();

        InfoCache infoCache=applicationContext.getBean("infoCache",InfoCache.class);
        infoCache.initCache();

        JopRunner jopRunner = applicationContext.getBean("jopRunner", JopRunner.class);
        jopRunner.startQuartz();

        JedisCluster jedisCluster=applicationContext.getBean("jedisClusterFactory",JedisCluster.class);


        // 启动通知事件的监控
//        EventNotifyRetryScheduling eventNotifyRetryScheduling = (EventNotifyRetryScheduling) applicationContext.getBean("eventNotifyRetryScheduling");
//        eventNotifyRetryScheduling.retryNotifyListener();
    }
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(applicationClass);
    }

    private static Class<BootstrapQuartzApi> applicationClass = BootstrapQuartzApi.class;
}